package com.netsdk.lht;

import com.netsdk.demo.util.CaseMenu;
import com.netsdk.demo.util.DateUtil;
import com.netsdk.demo.util.sql.EventDto;
import com.netsdk.demo.util.sql.JdbcUtils;
import com.netsdk.demo.util.sql.Trajectory;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.enumeration.*;
import com.netsdk.lib.structure.*;
import com.netsdk.lib.utils.Initialization;
import com.netsdk.module.entity.ShiJian;
import com.sun.jna.Pointer;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import static com.netsdk.lib.NetSDKLib.NET_MAX_DETECT_REGION_NUM;

public class RealLoadPicExDemo2 extends Initialization {

    int channel= -1;

    private final ConcurrentHashMap<String,List<Object>> cache = new ConcurrentHashMap<>();
    protected final static ConcurrentHashMap<Integer,String> channelMapping = new ConcurrentHashMap<>();
    {
        // 胜辛路-陈家山路-北侧2-南HG  已经使用过的：377
        channelMapping.put(383,"352");
        // 陈家山路-胜辛路-东侧-西HG 已经使用过的：
        channelMapping.put(359,"330");
        // 平城路-城北路-东侧-西HG 已经使用过的：
        channelMapping.put(367,"367");
        // 城北路-平成路-南侧-北HG 已经使用过的：368,379
        channelMapping.put(382,"368");
        // 平城路-城北路-西侧-东HG 已经使用过的：369,380
        channelMapping.put(386,"369");
        updateChannel();
    }

    // 同步 channel 号
    private void updateChannel() {
        String updateSQLTemplate = "update jyxq_qxjt_event set channel='%s' where channel='%s';";
        for (Map.Entry<Integer, String> entry : channelMapping.entrySet()) {
            Integer key = entry.getKey();
            String value = entry.getValue();
            if (!key.toString().equals(value)){
                String sql = String.format(updateSQLTemplate, value, key);
                JdbcUtils.update(sql);
            }
        }
    }


    NetSDKLib.LLong    attachHandle=new NetSDKLib.LLong(0);
    ShiJian sj = new ShiJian();
    public RealLoadPicExDemo2() throws SQLException {
    }

    /**
     * 订阅智能任务
     */
    public NetSDKLib.LLong AttachEventRealLoadPic() {
        // 先退订，设备不会对重复订阅作校验，重复订阅后会有重复的事件返回
        if(attachHandle.longValue()!=0){
            this.DetachEventRealLoadPic();
        }

        // 需要图片
        int bNeedPicture = 1;
        attachHandle = netSdk.CLIENT_RealLoadPictureEx(loginHandle, channel, EM_EVENT_TYPE.EVENT_IVS_ALL.getType(), bNeedPicture,
                RealLoadPicExDemo2.AnalyzerDataCB.getInstance(), null, null);
        if (attachHandle.longValue() != 0) {
            System.out.printf("Chn[%d] CLIENT_RealLoadPictureEx Success\n", channel);
        } else {
            System.out.printf("Chn[%d] CLIENT_RealLoadPictureEx Failed!LastError = %s\n", channel,
                    ToolKits.getErrorCode());
        }

        return attachHandle;
    }
    /**
     * 报警事件（智能）回调
     */
    private static class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack {
        private final File picturePath;
        private static RealLoadPicExDemo2.AnalyzerDataCB instance;


        private AnalyzerDataCB() {
            picturePath = new File("C:\\juyuan\\devtoos\\apache-tomcat-8.5.65\\webapps\\qxjtImg");
            if (!picturePath.exists()) {
                picturePath.mkdirs();
            }
        }

        public static RealLoadPicExDemo2.AnalyzerDataCB getInstance() {
            if (instance == null) {
                instance = new RealLoadPicExDemo2.AnalyzerDataCB();
            }
            return instance;
        }

        @Override
        public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize,
                          Pointer dwUser, int nSequence, Pointer reserved) throws UnsupportedEncodingException, SQLException {
            if (lAnalyzerHandle == null || lAnalyzerHandle.longValue() == 0) {
                return -1;
            }

            System.out.println("===================================EVENT RECEIVED=======================================");
//            System.out.println(Objects.requireNonNull(EM_EVENT_IVS_TYPE.getEventType(dwAlarmType)).getDescription());
            switch (Objects.requireNonNull(EM_EVENT_IVS_TYPE.getEventType(dwAlarmType))) {
                // 1行人检测
                case EVENT_IVS_TRAFFIC_PEDESTRAIN:
              {
                    EventDto dto = new EventDto();
                    dto.setEvent_name("行人检测");
                    dto.setEvent_code(dwAlarmType+"");
                    //创建事件对象
                    DEV_EVENT_TRAFFIC_THROW_INFO msg = new DEV_EVENT_TRAFFIC_THROW_INFO();
                    //加载事件新信息
                    ToolKits.GetPointerData(pAlarmInfo, msg);

                    // 通道号 对应设备
                    int nChannelID = msg.nChannelID;
                    System.out.println("nChannelID:" + nChannelID);
                    dto.setChannel(nChannelID+"");
                    //事件名称
                    byte[] szName = msg.szName;
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));
                    //UTC时间
                    NET_TIME_EX UTC = msg.UTC;
                    System.out.println("UTC:" + UTC.toStringTime());
                    dto.setEvent_utc_time(UTC.toStringTime());
                    //事件id
                    int nEventID = msg.nEventID;
                    dto.setEvent_id(nEventID+"");
                    //事件对应文件信息
                    NetSDKLib.NET_EVENT_FILE_INFO stuFileInfo = msg.stuFileInfo;
                    dto.setEvent_content(stuFileInfo.toString());
                    //图片分辨率
                    NetSDKLib.NET_RESOLUTION_INFO stuResolution = msg.stuResolution;
                    dto.setImg_fbl(stuResolution.toString());
                    //图片
                    int picSizes = 0;
                    NetSDKLib.NET_PIC_INFO stPicInfo = msg.stuObject.stPicInfo;
                  //图片保存
                  if (pBuffer != null) {
                      String pName = System.currentTimeMillis() + "related_EVENT_IVS_DREGS_UNCOVERED.jpg";
                      String picture = picturePath + "/" + pName;
                      if(null != pBuffer){
                          dto.setImg_name(pName);
                      }
                      ToolKits.savePicture(pBuffer, 0, dwBufSize, picture);
                  }
                    //抓图标志(按位),0位:"*",1位:"Timing",2位:"Manual",3位:"Marked",4位:"Event",5位:"Mosaic",6位:"Cutout"
                    int dwSnapFlagMask = msg.dwSnapFlagMask;
                    dto.setImg_mask(dwSnapFlagMask+"");
                    //事件动作,0表示脉冲事件,1表示持续性事件开始,2表示持续性事件结束
                    byte bEventAction = msg.bEventAction;
                    dto.setEvent_dz(String.valueOf(bEventAction));
                    //智能事件所属大类
                    int ClassType = msg.stuIntelliCommInfo.emClassType;
                    dto.setEvent_class(ClassType+"");
                    //对应车道号
                    int nLane = msg.nLane;
                    dto.setLane(nLane+"");
                    JdbcUtils.insert(dto);
                    break;
                }
                // 2停车检测
                case EVENT_IVS_TRAFFIC_PARKING:
                {
                    EventDto dto = new EventDto();
                    dto.setEvent_name("停车检测");
                    dto.setEvent_code(dwAlarmType+"");
                    DEV_EVENT_DREGS_UNCOVERED_INFO msg = new DEV_EVENT_DREGS_UNCOVERED_INFO();

                    ToolKits.GetPointerData(pAlarmInfo, msg);
                    // 通道号
                    int nChannelID = msg.nChannelID;
                    System.out.println("nChannelID:" + nChannelID);
                    dto.setChannel(nChannelID+"");
                    //事件名称
                    byte[] szName = msg.szName;
                    dto.setSzName( new String(msg.szName,"UTF-8").trim());
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));
                    //UTC时间
                    NET_TIME_EX UTC = msg.UTC;
                    System.out.println("UTC:" + UTC.toStringTime());
                    dto.setEvent_utc_time(UTC.toStringTime());
                    //事件id
                    int nEventID = msg.nEventID;
                    dto.setEvent_id(nEventID+"");
                    //智能事件所属大类
                    int ClassType = msg.emClassType;
                    dto.setEvent_class(ClassType+"");
                    //检测区域,[0,8191]
                    int nDetectRegionNum = msg.nDetectRegionNum;
                    dto.setRegion(nDetectRegionNum+"");
                    //事件对应文件信息
                    String stuDetectRegions = "";
                    NetSDKLib.NET_POINT[] stuDetectRegion = msg.stuDetectRegion;
                    for(int i = 0; i < NET_MAX_DETECT_REGION_NUM; i ++){
                        // System.out.println("stuDetectRegion[" + i + "]:" + stuDetectRegion[i].toString());
                        stuDetectRegions = stuDetectRegions + stuDetectRegion[i].toString()+",";
                    }
                    dto.setEvent_code(stuDetectRegions);
                    //车辆信息
                    DREGS_UNCOVERED_VEHICLE_INFO stuVehicleInfo = msg.stuVehicleInfo;

                    dto.setStu_Vehicle_Info(new String(stuVehicleInfo.szPlateNumber).trim());
                    //图片保存
                    if (pBuffer != null) {
                        String pName = System.currentTimeMillis() + "related_EVENT_IVS_DREGS_UNCOVERED.jpg";
                        String picture = picturePath + "/" + pName;
                        if(null != pBuffer){
                            dto.setImg_name(pName);
                        }
                        ToolKits.savePicture(pBuffer, 0, dwBufSize, picture);
                        System.out.println("图片:" + picture);
                    }
                    JdbcUtils.insert(dto);

                    break;
                }
                //交通抛洒物品事件
               case EVENT_IVS_TRAFFIC_THROW : {
                    EventDto dto = new EventDto();
                    dto.setEvent_name("交通抛洒物品事件");
                    dto.setEvent_code(dwAlarmType+"");
                    DEV_EVENT_TRAFFIC_THROW_INFO msg = new DEV_EVENT_TRAFFIC_THROW_INFO();

                    ToolKits.GetPointerData(pAlarmInfo, msg);

                    // 通道号
                    int nChannelID = msg.nChannelID;
                    System.out.println("nChannelID:" + nChannelID);
                    dto.setChannel(nChannelID+"");
                    //事件名称
                    byte[] szName = msg.szName;
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));
                    //UTC时间
                    NET_TIME_EX UTC = msg.UTC;
                    System.out.println("UTC:" + UTC.toStringTime());
                    dto.setEvent_utc_time(UTC.toStringTime());
                    //事件id
                    int nEventID = msg.nEventID;
                    dto.setEvent_id(nEventID+"");
                    //事件对应文件信息
                    NetSDKLib.NET_EVENT_FILE_INFO stuFileInfo = msg.stuFileInfo;
                    dto.setEvent_content(stuFileInfo.toString());
                    //图片分辨率
                    NetSDKLib.NET_RESOLUTION_INFO stuResolution = msg.stuResolution;
                    dto.setImg_fbl(stuResolution.toString());
                    //图片
                    int picSizes = 0;
                    NetSDKLib.NET_PIC_INFO stPicInfo = msg.stuObject.stPicInfo;
                    dto.setImg_name(stPicInfo.toString());
                   //图片保存
                   if (pBuffer != null) {
                       String pName = System.currentTimeMillis() + "related_EVENT_IVS_DREGS_UNCOVERED.jpg";
                       String picture = picturePath + "/" + pName;
                       if(null != pBuffer){
                           dto.setImg_name(pName);
                       }
                       ToolKits.savePicture(pBuffer, 0, dwBufSize, picture);
                   }
                    //抓图标志(按位),0位:"*",1位:"Timing",2位:"Manual",3位:"Marked",4位:"Event",5位:"Mosaic",6位:"Cutout"
                    int dwSnapFlagMask = msg.dwSnapFlagMask;
                    dto.setImg_mask(dwSnapFlagMask+"");
                    //事件动作,0表示脉冲事件,1表示持续性事件开始,2表示持续性事件结束
                    byte bEventAction = msg.bEventAction;
                    dto.setEvent_dz(String.valueOf(bEventAction));
                    //智能事件所属大类
                    int ClassType = msg.stuIntelliCommInfo.emClassType;
                    dto.setEvent_class(ClassType+"");
                    //对应车道号
                    int nLane = msg.nLane;
                    dto.setLane(nLane+"");
                    JdbcUtils.insert(dto);
                    break;
                }
                // 逆行检测
               case EVENT_IVS_TRAFFIC_RETROGRADE:
                {
                    EventDto dto = new EventDto();
                    dto.setEvent_name("逆行检测");
                    dto.setEvent_code(dwAlarmType+"");
                    DEV_EVENT_DREGS_UNCOVERED_INFO msg = new DEV_EVENT_DREGS_UNCOVERED_INFO();

                    ToolKits.GetPointerData(pAlarmInfo, msg);
                    // 通道号
                    int nChannelID = msg.nChannelID;
                    System.out.println("nChannelID:" + nChannelID);
                    dto.setChannel(nChannelID+"");
                    //事件名称
                    byte[] szName = msg.szName;
                    dto.setSzName( new String(msg.szName,"UTF-8").trim());
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));
                    //UTC时间
                    NET_TIME_EX UTC = msg.UTC;
                    System.out.println("UTC:" + UTC.toStringTime());
                    dto.setEvent_utc_time(UTC.toStringTime());
                    //事件id
                    int nEventID = msg.nEventID;
                    dto.setEvent_id(nEventID+"");
                    //智能事件所属大类
                    int ClassType = msg.emClassType;
                    dto.setEvent_class(ClassType+"");
                    //检测区域,[0,8191]
                    int nDetectRegionNum = msg.nDetectRegionNum;
                    dto.setRegion(nDetectRegionNum+"");
                    //事件对应文件信息
                    String stuDetectRegions = "";
                    NetSDKLib.NET_POINT[] stuDetectRegion = msg.stuDetectRegion;
                    for(int i = 0; i < NET_MAX_DETECT_REGION_NUM; i ++){
                        stuDetectRegions = stuDetectRegions + stuDetectRegion[i].toString()+",";
                    }
                    dto.setEvent_code(stuDetectRegions);
                    //车辆信息
                    DREGS_UNCOVERED_VEHICLE_INFO stuVehicleInfo = msg.stuVehicleInfo;
                    dto.setStu_Vehicle_Info(new String(stuVehicleInfo.szPlateNumber).trim());
                    //图片保存
                    if (pBuffer != null) {
                        String pName = System.currentTimeMillis() + "related_EVENT_IVS_DREGS_UNCOVERED.jpg";
                        String picture = picturePath + "/" + pName;
                        if(null != pBuffer){
                            dto.setImg_name(pName);
                        }
                        ToolKits.savePicture(pBuffer, 0, dwBufSize, picture);
                    }
                    JdbcUtils.insert(dto);
                    break;
                }
                // 倒车检测
               case EVENT_IVS_TRAFFIC_BACKING:
                {
                    EventDto dto = new EventDto();
                    dto.setEvent_name("倒车检测");
                    dto.setEvent_code(dwAlarmType+"");
                    DEV_EVENT_DREGS_UNCOVERED_INFO msg = new DEV_EVENT_DREGS_UNCOVERED_INFO();

                    ToolKits.GetPointerData(pAlarmInfo, msg);
                    // 通道号
                    int nChannelID = msg.nChannelID;
                    System.out.println("nChannelID:" + nChannelID);
                    dto.setChannel(nChannelID+"");
                    //事件名称
                    byte[] szName = msg.szName;
                    dto.setSzName( new String(msg.szName,"UTF-8").trim());
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));
                    //UTC时间
                    NET_TIME_EX UTC = msg.UTC;
                    System.out.println("UTC:" + UTC.toStringTime());
                    dto.setEvent_utc_time(UTC.toStringTime());
                    //事件id
                    int nEventID = msg.nEventID;
                    dto.setEvent_id(nEventID+"");
                    //智能事件所属大类
                    int ClassType = msg.emClassType;
                    dto.setEvent_class(ClassType+"");
                    //检测区域,[0,8191]
                    int nDetectRegionNum = msg.nDetectRegionNum;
                    dto.setRegion(nDetectRegionNum+"");
                    //事件对应文件信息
                    String stuDetectRegions = "";
                    NetSDKLib.NET_POINT[] stuDetectRegion = msg.stuDetectRegion;
                    for(int i = 0; i < NET_MAX_DETECT_REGION_NUM; i ++){
                        stuDetectRegions = stuDetectRegions + stuDetectRegion[i].toString()+",";
                    }
                    dto.setEvent_code(stuDetectRegions);
                    //车辆信息
                    DREGS_UNCOVERED_VEHICLE_INFO stuVehicleInfo = msg.stuVehicleInfo;
                    dto.setStu_Vehicle_Info(new String(stuVehicleInfo.szPlateNumber).trim());
                    //图片保存
                    if (pBuffer != null) {
                        String pName = System.currentTimeMillis() + "related_EVENT_IVS_DREGS_UNCOVERED.jpg";
                        String picture = picturePath + "/" + pName;
                        if(null != pBuffer){
                            dto.setImg_name(pName);
                        }
                        ToolKits.savePicture(pBuffer, 0, dwBufSize, picture);
                    }
                    JdbcUtils.insert(dto);
                    break;
                }
                // 交通非机动车事件检测
              case EVENT_IVS_TRAFFIC_NONMOTOR:
                {
                    System.out.println("交通非机动车事件检测, code = " + dwAlarmType);
                    DEV_EVENT_TRAFFIC_NONMOTOR_INFO msg = new DEV_EVENT_TRAFFIC_NONMOTOR_INFO();
                    ToolKits.GetPointerData(pAlarmInfo, msg);
                    // 通道号
                    int nChannelID = msg.nChannelID;
                    System.out.println("nChannelID:" + nChannelID);
                    // 动作
                    int nAction = msg.nAction;
                    System.out.println("nAction:" + nAction);
                    // 规则
                    int nRuleId = msg.nRuleId;
                    System.out.println("nRuleId:" + nRuleId);
                    // 触发方式
                    int emTriggerType = msg.emTriggerType;
                    System.out.println("emTriggerType:" + emTriggerType + "," + EM_TRIGGER_TYPE.getNoteByValue(emTriggerType));
                    //事件名称
                    byte[] szName = msg.szName;
                    System.out.println("szName UTF-8:" + new String(szName,"UTF-8").trim());
                    System.out.println("szName GBK:" + new String(szName,"GBK").trim());
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    System.out.println("pts:" + new Date((long) pts));
                    //UTC时间
                    NET_TIME_EX UTC = msg.UTC;
                    System.out.println("UTC:" + UTC.toStringTime());
                    //事件id
                    int nEventID = msg.nEventID;
                    System.out.println("nEventID:" + nEventID);
                    EventDto dto = new EventDto();
                    //图片保存
                    if (pBuffer != null && dwBufSize > 0) {
                        System.out.println("basic picture received!");
                        String pName = System.currentTimeMillis() + "related_TrafficNoMotor_basic.jpg";
                        String bigPicture = picturePath + "\\" + pName;
                        if(null != pBuffer){
                            dto.setBigPicture(pName);
                        }
                        ToolKits.savePicture(pBuffer, dwBufSize, bigPicture);
                    }
                    //图片保存
                    if (pBuffer != null) {
                        String pName = System.currentTimeMillis() + "related_EVENT_IVS_DREGS_UNCOVERED.jpg";
                        String picture = picturePath + "/" + pName;
                        if(null != pBuffer){
                            dto.setImg_name(pName);
                        }
                        ToolKits.savePicture(pBuffer, 0, dwBufSize, picture);
                    }
                    if (pBuffer != null && dwBufSize > 0 && msg.stuNonMotor.stuSceneImage.nLength > 0) {
                        System.out.println("Scene picture received!");
                        String pName = System.currentTimeMillis() + "related_TrafficNoMotor_scene.jpg";
                        String scenePicture = picturePath + "\\" + pName;
                        if(null != pBuffer){
                            dto.setScenePicture(pName);
                        }
                        ToolKits.savePicture(pBuffer, msg.stuNonMotor.stuSceneImage.nOffSet, msg.stuNonMotor.stuSceneImage.nLength , scenePicture);
                    }
                    if (pBuffer != null && dwBufSize > 0 && msg.stuNonMotor.stuFaceSceneImage.nLength > 0) {
                        System.out.println("face picture received!");
                        String pName = System.currentTimeMillis() + "related_TrafficNoMotor_face.jpg";
                        String facePicture = picturePath + "\\" + pName;
                        if(null != pBuffer){
                            dto.setFacePicture(pName);
                        }
                        ToolKits.savePicture(pBuffer, msg.stuNonMotor.stuFaceSceneImage.nOffSet, msg.stuNonMotor.stuFaceSceneImage.nLength , facePicture);
                    }
                    //图片保存
                    if (pBuffer != null && dwBufSize > 0 && msg.stuCommInfo.nPictureNum > 0) {
                        System.out.println(msg.stuCommInfo.nPictureNum + " pictures received!");
                        for(int i = 0; i < msg.stuCommInfo.nPictureNum; i ++){
                            String pName = System.currentTimeMillis() + "related_TrafficJam_common_"+i+".jpg";
                            String bigPicture = picturePath + "\\" + pName;
                            if(null != pBuffer){
                                dto.setBigPicture(StringUtils.isNotEmpty(dto.getBigPicture()) ? dto.getBigPicture() + ","+pName : ""+pName );
                            }
                            ToolKits.savePicture(pBuffer, msg.stuCommInfo.stuPicInfos[i].nOffset, msg.stuCommInfo.stuPicInfos[i].nLength, bigPicture);
                        }
                    }

                    dto.setEvent_name("交通非机动车事件检测");
                    dto.setEvent_code(dwAlarmType+"");
                    dto.setChannel(nChannelID+"");
                    dto.setnAction(nAction+"");
                    dto.setRule_Id(nRuleId+"");
                    dto.setEvent_utc_time(UTC.toStringTime());
                    dto.setSzName(new String(msg.szName,"UTF-8").trim());
                    dto.setTriggertType(emTriggerType+"");
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));
                    dto.setEvent_id(nEventID+"");
                    dto.setEvent_utc_time(UTC.toStringTime());
                    JdbcUtils.insert(dto);
                    break;
                }
                // 交通拥堵
                case EVENT_IVS_TRAFFICJAM:
                {
                    EventDto dto = new EventDto();
                    System.out.println("交通拥堵事件, code = " + dwAlarmType);
                    dto.setEvent_name("交通拥堵事件");
                    dto.setEvent_code(dwAlarmType+"");
                    NetSDKLib.DEV_EVENT_TRAFFICJAM_INFO msg = new NetSDKLib.DEV_EVENT_TRAFFICJAM_INFO();
                    ToolKits.GetPointerData(pAlarmInfo, msg);
                    // 通道号
                    int nChannelID = msg.nChannelID;
                    dto.setChannel(nChannelID+"");
                    System.out.println("nChannelID:" + nChannelID);
                    // 车道号
                    int nLane = msg.nLane;
                    System.out.println("nLane:" + nLane);
                    dto.setLane(nLane+"");
                    // 报警时间间隔
                    int nAlarmIntervalTime = msg.nAlarmIntervalTime;
                    System.out.println("nAlarmIntervalTime:" + nAlarmIntervalTime);
                    dto.setnAlarmIntervalTime(nAlarmIntervalTime+"");
                    //事件名称
                    byte[] szName = msg.szName;
                    System.out.println("szName UTF-8:" + new String(szName,"UTF-8").trim());
                    System.out.println("szName GBK:" + new String(szName,"GBK").trim());
                    dto.setSzName(new String(szName,"UTF-8").trim());
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    System.out.println("pts:" + new Date((long) pts));
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));

                    //事件id
                    int nEventID = msg.nEventID;
                    System.out.println("nEventID:" + nEventID);
                    dto.setEvent_id(nEventID+"");
                    //图片保存
                    if (pBuffer != null && dwBufSize > 0 && msg.stCommInfo.nPictureNum > 0) {
                        System.out.println(msg.stCommInfo.nPictureNum + " pictures received!");
                        for(int i = 0; i < msg.stCommInfo.nPictureNum; i ++){
                            String pName = System.currentTimeMillis() + "related_TrafficJam_common_" + i + ".jpg";
                            String bigPicture = picturePath + "\\" + pName;
                            if(null != pBuffer){
                                dto.setBigPicture(StringUtils.isNotEmpty(dto.getBigPicture()) ? dto.getBigPicture() + ","+pName : ""+pName );
                            }

                            ToolKits.savePicture(pBuffer, msg.stCommInfo.stuPicInfos[i].nOffset, msg.stCommInfo.stuPicInfos[i].nLength, bigPicture);
                        }
                    }
                    //交通车辆信息扩展
                    NET_TRAFFICCAR_INFO_EXTERN stInfo = new NET_TRAFFICCAR_INFO_EXTERN();
                    ToolKits.GetPointerData(msg.stTrafficCar.pTrafficInfoExtern,stInfo);
                    System.out.println("stInfo.bAverageSpeed = " + stInfo.bAverageSpeed);
                    System.out.println("stInfo.bSpaceOcpRatio = " + stInfo.bSpaceOcpRatio);
                    System.out.println("stInfo.dAverageSpeed = " + stInfo.dAverageSpeed);
                    System.out.println("stInfo.dSpaceOcpRatio = " + stInfo.dSpaceOcpRatio);
                    System.out.println("stInfo.nContainerNumber = " + stInfo.nContainerNumber);
                    System.out.println("stInfo.nContainerTextNum = " + stInfo.nContainerTextNum);
                    String nContainerTextNum = "";
                    for(int i = 0; i < stInfo.nContainerTextNum; i ++){
                        byte[] tmp = new byte[64];
                        System.arraycopy(stInfo.szContainerText, i * 64, stInfo.nContainerTextNum, 0, 64);
                        String text = new String(tmp).trim();
                        System.out.println("stInfo.nContainerTextNum[" + i + "] = " + text);
                        nContainerTextNum = nContainerTextNum + text + ",";
                    }
                    dto.setnContainerTextNum(nContainerTextNum);
                    JdbcUtils.insert(dto);

                    break;
                }
                // 交通事故事件
                case EVENT_IVS_TRAFFIC_REAREND_ACCIDENT:
                {
                    System.out.println("交通事故事件, code = " + dwAlarmType);
                    DEV_EVENT_TRAFFIC_REAREND_ACCIDENT_INFO msg = new DEV_EVENT_TRAFFIC_REAREND_ACCIDENT_INFO();
                    ToolKits.GetPointerData(pAlarmInfo, msg);
                    // 通道号
                    EventDto dto = new EventDto();
                    int nChannelID = msg.nChannelID;
                    System.out.println("nChannelID:" + nChannelID);
                    // 动作
                    int nAction = msg.nAction;
                    System.out.println("nAction:" + nAction);
                    // 车道号
                    int nLaneID = msg.nLaneID;
                    System.out.println("nLaneID:" + nLaneID);
                    // 抓拍过程
                    int emCaptureProcess = msg.emCaptureProcess;
                    System.out.println("emCaptureProcess:" + emCaptureProcess + "," + EM_CAPTURE_PROCESS_END_TYPE.getNoteByValue(emCaptureProcess));
                    //事件名称
                    byte[] szName = msg.szName;
                    System.out.println("szName UTF-8:" + new String(szName,"UTF-8").trim());
                    System.out.println("szName GBK:" + new String(szName,"GBK").trim());
                    //相对事件时间戳(单位是毫秒)
                    double pts = msg.PTS;
                    System.out.println("pts:" + new Date((long) pts));
                    //UTC时间
                    NET_TIME_EX UTC = msg.UTC;
                    System.out.println("UTC:" + UTC.toStringTime());
                    //事件id
                    int nEventID = msg.nEventID;
                    System.out.println("nEventID:" + nEventID);
                    //图片保存
                    if (pBuffer != null && dwBufSize > 0 && msg.stuCommInfo.nPictureNum > 0) {
                        System.out.println(msg.stuCommInfo.nPictureNum + " pictures received!");
                        for(int i = 0; i < msg.stuCommInfo.nPictureNum; i ++){
                            String pName = System.currentTimeMillis() + "related_TrafficAccident_common_" + i + ".jpg";
                            String bigPicture = picturePath + "\\" + pName;
                            if(null != pBuffer){
                                dto.setBigPicture(StringUtils.isNotEmpty(dto.getBigPicture()) ? dto.getBigPicture() + ","+pName : ""+pName );
                            }
                            ToolKits.savePicture(pBuffer, msg.stuCommInfo.stuPicInfos[i].nOffset, msg.stuCommInfo.stuPicInfos[i].nLength, bigPicture);
                        }
                    }

                    dto.setEvent_name("交通事故事件");
                    dto.setEvent_code(dwAlarmType+"");
                    dto.setChannel(nChannelID+"");
                    dto.setnAction(nAction+"");
                    dto.setLane(nLaneID+"");
                    dto.setEvent_utc_time(UTC.toStringTime());
                    dto.setEmCaptureProcess(emCaptureProcess+"");
                    dto.setSzName(new String(szName,"UTF-8").trim());
                    dto.setEvent_time(DateUtil.format(new Date((long) pts), "yyyy-MM-dd HH:mm:ss.SSS"));
                    dto.setEvent_id(nEventID+"");
                    JdbcUtils.insert(dto);
                    break;
                }

                //交通流量事件
                case  EVENT_IVS_TRAFFIC_FLOWSTATE : {
                    System.out.println("交通流量事件, code = " + dwAlarmType);
                    try {
                        NetSDKLib.DEV_EVENT_TRAFFIC_FLOW_STATE msg = new NetSDKLib.DEV_EVENT_TRAFFIC_FLOW_STATE();
                        ToolKits.GetPointerData(pAlarmInfo, msg);
                        // 通道号
                        int nChannelID = msg.nChannelID;
                        System.out.println("nChannelID:" + nChannelID);
                        //相对事件时间戳(单位是毫秒)
                        double pts = msg.PTS;
                        //UTC时间 事件发生时间
                        NetSDKLib.NET_TIME_EX UTC = msg.UTC;
                        System.out.println("UTC:" + UTC.toStringTime());
                        //事件id
                        int nEventID = msg.nEventID;
                        //流量状态数量
                        int nStateNum = msg.nStateNum;
                        //该事件触发的预置点
                        int nPresetID = msg.stuIntelliCommInfo.nPresetID;
                        //智能事件所属大类
                        String emClassType = EM_CLASS_TYPE.getNoteByValue(msg.stuIntelliCommInfo.emClassType);
                        //流量状态数量
                        int nStopVehiclenum = msg.nStopVehiclenum;
                        //流量状态数量
                        int nDetectionAreaVehicleNum = msg.nDetectionAreaVehicleNum;
                        System.out.println("车辆总数: "+ nDetectionAreaVehicleNum);
                        String p_Name ="";
                        System.out.println("图片, " + pBuffer);
                        //图片保存,交通流量没有图片

                        List<EventDto> list = new ArrayList<>();
                        List<Trajectory> list2 = new ArrayList<>();

                        List<Map<String, Object>> Traficlist;
                        int commaIndex =0;

                        for (int i = 0; i < nStateNum; i++) {
                            // 车道号
                            if(msg.stuStates[i].nLane  == 0){
                                // 无效的车道
                                continue;
                            };
                            System.out.println(msg.stuStates[i]);
                            //车道流量
                            int nums = msg.stuStates[i].dwFlow;
                            System.out.println("车辆数:" + nums);

                            // 有车流才生成轨迹
                            if(msg.stuStates[i].nLane!=0 && msg.stuStates[i].dwFlow >0 ){
                                //交通流量事件，转换实体类
                                EventDto e  = EventDtoUtil.toEventDto(msg,msg.stuStates[i]);
                                // 重新设置 chennelId
                                String channelId = channelMapping.getOrDefault(msg.nChannelID, msg.nChannelID + "");
                                e.setChannel(channelId);
                                list.add(e);
                                //车辆轨迹设置
                                for (EventDto eventDto : list) {
                                    eventDto.setState_num(nums+"");
                                    JdbcUtils.insert(eventDto);
                                }

                                try {
                                    // 生成车道轨迹
                                    String sql3 = "select t.nJun,t.device_address,t.nChannel,t.nLane,t.nLaneNo,t.direction,t.cog,t.size," +
                                            "t.usetime,t.befor,t.total,t.zb1,t.zb2,t.zb3,t.zb4,t.zb5,t.zb6,t.zb7,t.zb8,t.alltime, t.offset  "
                                            + ",t.green  from zbset t where nChannel=? and nLaneNo=? and zb1 is not null ";
                                    List<Map<String, Object>> zblist = JdbcUtils.queryBean(sql3, e.getChannel(),(msg.stuStates[i].nLane));

                                    if (null != zblist && zblist.size() > 0) {
                                        for (int w = 0; w < zblist.size(); w++) {
                                            Integer delay=0;
                                            String nLane = zblist.get(w).get("nLane").toString() ;
                                            String direction = zblist.get(w).get("direction").toString() ;
                                            String zb1 = zblist.get(w).get("zb1").toString();
                                            String zb2 = zblist.get(w).get("zb2").toString() ;
                                            String zb3 = zblist.get(w).get("zb3").toString();
                                            String zb4 = zblist.get(w).get("zb4").toString() ;
                                            String zb5 = zblist.get(w).get("zb5").toString();
                                            String zb6 = zblist.get(w).get("zb6").toString();
                                            String zb7 = zblist.get(w).get("zb7").toString();
                                            String cog = zblist.get(w).get("cog").toString() ;
                                            String  green = zblist.get(w).get("green").toString() ;
                                            String usetime = zblist.get(w).get("usetime").toString();
                                            Integer usetime2=Integer.parseInt(zblist.get(w).get("usetime").toString());
                                            Integer size = Integer.parseInt(zblist.get(w).get("size").toString());
                                            String alltime = zblist.get(w).get("alltime").toString();
                                            Integer befor = Integer.parseInt(zblist.get(w).get("befor").toString());
                                            Integer total = Integer.parseInt(zblist.get(w).get("total").toString());
                                            String nLaneNo=zblist.get(w).get("nLaneNo").toString() ;
                                            Integer offset  = Integer.parseInt(zblist.get(w).get("offset").toString());
                                                //限制最大过车量
                                                //車少情況
                                                for (int j = 0; j < nums; j++) {
//                                                    if(nLane.equals("LSDX-01") || nLane.equals("LSDX-02")
//                                                            || nLane.equals("PCXD-03") || nLane.equals("PCDX-01")){
//                                                        if(direction.equals("直行")){
//                                                            if(j==0){
//                                                                delay=25;
//                                                            }
//                                                            delay=delay+(usetime2-25)/nums;
//                                                        }else{
//                                                            delay=delay+(usetime2-25)/nums;
//                                                        }
//                                                    }else{
//                                                        delay=delay+(usetime2-2)/nums;
//
                                                    Trajectory t = new Trajectory();
                                                    t.setUtc(UTC.toStringTime());
                                                    int setpSize = 1;
                                                    if("左转".equals(direction)){
                                                        setpSize = 20;
                                                    }
                                                    // 添加随机值，使车辆错开
                                                    LocalDateTime localDateTime = toLocalDateTime(UTC).plusSeconds( offset + setpSize+delay);
                                                    delay += getRandom();
                                                    t.setTime(formateLocalDateTime(localDateTime));
                                                    t.setChannel(e.getChannel());
                                                    t.setOrderno("1");
                                                    t.setSog("10");
                                                    t.setTimeout("100");
                                                    t.setMmsi("100");
                                                    t.setHeading("0");
                                                    t.setImo("0");
                                                    t.setCallsign("0");
                                                    t.setInlandShipMark("false");
                                                    t.setOrdercar(j+"");
                                                    t.setState("0");

                                                    t.setName("tt");
                                                    t.setDelay(delay.toString());
                                                    t.setNlane(nLane);
                                                    t.setCog(cog);
                                                    t.setDirection(direction);
                                                    commaIndex=zb1.indexOf(',');
                                                    t.setLon(zb1.substring(0, commaIndex));
                                                    t.setLat(zb1.substring(commaIndex + 1));
                                                    t.setGreen(green);
                                                    t.setBefor(befor+"");
                                                    t.setUsetime(usetime);
                                                    t.setAlltime(alltime);
                                                    t.setnLaneNo(nLaneNo);

                                                    if(j==102){
                                                        t.setShipTypeName("面包车");
                                                        t.setLength("6");
                                                        t.setWidth("3");
                                                        t.setShipTypeClassName("中型车");
                                                    }else if(j==8){
                                                        t.setShipTypeName("公交车");
                                                        t.setLength("10");
                                                        t.setWidth("3.5");
                                                        t.setShipTypeClassName("大型车");
                                                    }else if(j==4){
                                                        t.setShipTypeName("出租车");
                                                        t.setLength("4");
                                                        t.setWidth("2");
                                                        t.setShipTypeClassName("小轿车");
                                                    }else if(j==9){
                                                        t.setShipTypeName("大货车");
                                                        t.setLength("10");
                                                        t.setWidth("3.5");
                                                        t.setShipTypeClassName("大型车");
                                                    }else{
                                                        t.setShipTypeName("私家车");
                                                        t.setLength("4");
                                                        t.setWidth("2");
                                                        t.setShipTypeClassName("小轿车");
                                                    }
                                                    list2.add(t);

                                                    Trajectory t11 = new Trajectory();
                                                    LocalDateTime localDateTime1 = localDateTime.plusSeconds(1);
                                                    t11.setTime(formateLocalDateTime(localDateTime1));
                                                    t11.setUtc(UTC.toStringTime());
                                                    t11.setChannel(t.getChannel());
                                                    t11.setOrderno("2");
                                                    t11.setSog("10");
                                                    t11.setTimeout("100");
                                                    t11.setMmsi(t.getMmsi());
                                                    t11.setHeading("0");
                                                    t11.setImo("0");
                                                    t11.setCallsign("0");
                                                    t11.setInlandShipMark("false");
                                                    t11.setOrdercar(j+"");
                                                    t11.setShipTypeName(t.getShipTypeName());
                                                    t11.setLength(t.getLength());
                                                    t11.setWidth(t.getWidth());
                                                    t11.setShipTypeClassName(t.getShipTypeClassName());

                                                    t11.setName("tt");
                                                    t11.setDelay(delay.toString());
                                                    t11.setNlane(nLane);
                                                    t11.setCog(cog);
                                                    t11.setDirection(direction);
                                                    commaIndex=zb2.indexOf(',');
                                                    t11.setLon(zb2.substring(0, commaIndex));
                                                    t11.setLat(zb2.substring(commaIndex + 1));
                                                    t11.setState("0");
                                                    t11.setGreen(green);
                                                    t11.setBefor(befor+"");
                                                    t11.setUsetime(usetime);
                                                    t11.setAlltime(alltime);
                                                    t11.setnLaneNo(nLaneNo);
                                                    list2.add(t11);
                                                    Trajectory t12 = new Trajectory();
                                                    LocalDateTime localDateTime2 = localDateTime1.plusSeconds(1);
                                                    t12.setTime(formateLocalDateTime(localDateTime2));
                                                    t12.setUtc(UTC.toStringTime());
                                                    t12.setChannel(t.getChannel());
                                                    t12.setOrderno("3");
                                                    t12.setSog("10");
                                                    t12.setTimeout("100");
                                                    t12.setMmsi(t.getMmsi());
                                                    t12.setHeading("0");
                                                    t12.setImo("0");
                                                    t12.setCallsign("0");
                                                    t12.setInlandShipMark("false");
                                                    t12.setOrdercar(j+"");
                                                    t12.setShipTypeName(t.getShipTypeName());
                                                    t12.setLength(t.getLength());
                                                    t12.setWidth(t.getWidth());
                                                    t12.setShipTypeClassName(t.getShipTypeClassName());

                                                    t12.setName("tt");
                                                    t12.setDelay(delay.toString());
                                                    t12.setNlane(nLane);
                                                    t12.setCog(cog);
                                                    t12.setDirection(direction);
                                                    commaIndex=zb3.indexOf(',');
                                                    t12.setLon(zb3.substring(0, commaIndex));
                                                    t12.setLat(zb3.substring(commaIndex + 1));
                                                    t12.setState("0");
                                                    t12.setGreen(green);
                                                    t12.setBefor(befor+"");
                                                    t12.setUsetime(usetime);
                                                    t12.setAlltime(alltime);
                                                    t12.setnLaneNo(nLaneNo);
                                                    list2.add(t12);
                                                    Trajectory t13 = new Trajectory();
                                                    LocalDateTime localDateTime3 = localDateTime2.plusSeconds(1);
                                                    t13.setTime(formateLocalDateTime(localDateTime3));
//                                                    t13.setTime(t.getTime());
                                                    t13.setUtc(UTC.toStringTime());
                                                    t13.setChannel(t.getChannel());
                                                    t13.setOrderno("4");
                                                    t13.setSog("10");
                                                    t13.setTimeout("100");
                                                    t13.setMmsi(t.getMmsi());
                                                    t13.setHeading("0");
                                                    t13.setImo("0");
                                                    t13.setCallsign("0");
                                                    t13.setInlandShipMark("false");
                                                    t13.setOrdercar(j+"");
                                                    t13.setShipTypeName(t.getShipTypeName());
                                                    t13.setLength(t.getLength());
                                                    t13.setWidth(t.getWidth());
                                                    t13.setShipTypeClassName(t.getShipTypeClassName());

                                                    t13.setName("tt");
                                                    t13.setDelay(delay.toString());
                                                    t13.setNlane(nLane);
                                                    t13.setCog(cog);
                                                    t13.setDirection(direction);
                                                    commaIndex=zb4.indexOf(',');
                                                    t13.setLon(zb4.substring(0, commaIndex));
                                                    t13.setLat(zb4.substring(commaIndex + 1));
                                                    t13.setState("0");
                                                    t13.setGreen(green);
                                                    t13.setBefor(befor+"");
                                                    t13.setUsetime(usetime);
                                                    t13.setAlltime(alltime);
                                                    t13.setnLaneNo(nLaneNo);
                                                    list2.add(t13);
                                                    Trajectory t14 = new Trajectory();
                                                    LocalDateTime localDateTime4 = localDateTime3.plusSeconds(1);
                                                    t14.setTime(formateLocalDateTime(localDateTime4));
//                                                    t14.setTime(t.getTime());
                                                    t14.setUtc(UTC.toStringTime());
                                                    t14.setChannel(t.getChannel());
                                                    t14.setOrderno("5");
                                                    t14.setDirection("2");
                                                    t14.setSog("10");
                                                    t14.setTimeout("100");
                                                    t14.setMmsi(t.getMmsi());
                                                    t14.setCog("0");
                                                    t14.setHeading("0");
                                                    t14.setImo("0");
                                                    t14.setCallsign("0");
                                                    t14.setInlandShipMark("false");
                                                    t14.setNlane("2");
                                                    t14.setOrdercar(j+"");
                                                    t14.setShipTypeName(t.getShipTypeName());
                                                    t14.setLength(t.getLength());
                                                    t14.setWidth(t.getWidth());
                                                    t14.setShipTypeClassName(t.getShipTypeClassName());
                                                    t14.setState("0");

                                                    t14.setName("tt");
                                                    t14.setDelay(delay.toString());
                                                    t14.setNlane(nLane);
                                                    t14.setCog(cog);
                                                    t14.setDirection(direction);
                                                    commaIndex=zb5.indexOf(',');
                                                    t14.setLon(zb5.substring(0, commaIndex));
                                                    t14.setLat(zb5.substring(commaIndex + 1));
                                                    t14.setState("0");
                                                    t14.setGreen(green);
                                                    t14.setBefor(befor+"");
                                                    t14.setUsetime(usetime);
                                                    t14.setAlltime(alltime);
                                                    t14.setnLaneNo(nLaneNo);
                                                    list2.add(t14);
                                                    Trajectory t15 = new Trajectory();
                                                    LocalDateTime localDateTime5 = localDateTime4.plusSeconds(1);
                                                    t15.setTime(formateLocalDateTime(localDateTime5));
//                                                    t15.setTime(t.getTime());
                                                    t15.setUtc(UTC.toStringTime());
                                                    t15.setChannel(t.getChannel());
                                                    t15.setOrderno("6");
                                                    t15.setDirection("2");
                                                    t15.setSog("10");
                                                    t15.setTimeout("100");
                                                    t15.setMmsi(t.getMmsi());
                                                    t15.setCog("0");
                                                    t15.setHeading("0");
                                                    t15.setImo("0");
                                                    t15.setCallsign("0");
                                                    t15.setInlandShipMark("false");
                                                    t15.setNlane("2");
                                                    t15.setOrdercar(j+"");
                                                    t15.setShipTypeName(t.getShipTypeName());
                                                    t15.setLength(t.getLength());
                                                    t15.setWidth(t.getWidth());
                                                    t15.setShipTypeClassName(t.getShipTypeClassName());
                                                    t15.setState("0");

                                                    t15.setName("tt");
                                                    t15.setDelay(delay.toString());
                                                    t15.setNlane(nLane);
                                                    t15.setCog(cog);
                                                    t15.setDirection(direction);
                                                    commaIndex=zb6.indexOf(',');
                                                    t15.setLon(zb6.substring(0, commaIndex));
                                                    t15.setLat(zb6.substring(commaIndex + 1));
                                                    t15.setState("0");
                                                    t15.setGreen(green);
                                                    t15.setBefor(befor+"");
                                                    t15.setUsetime(usetime);
                                                    t15.setAlltime(alltime);
                                                    t15.setnLaneNo(nLaneNo);
                                                    list2.add(t15);
                                                    Trajectory t16 = new Trajectory();
                                                    LocalDateTime localDateTime6 = localDateTime5.plusSeconds(1);
                                                    t16.setTime(formateLocalDateTime(localDateTime6));
//                                                    t16.setTime(t.getTime());
                                                    t16.setUtc(UTC.toStringTime());
                                                    t16.setChannel(t.getChannel());
                                                    t16.setOrderno("7");
                                                    t16.setDirection("2");
                                                    t16.setSog("10");
                                                    t16.setTimeout("100");
                                                    t16.setMmsi(t.getMmsi());
                                                    t16.setCog("0");
                                                    t16.setHeading("0");
                                                    t16.setImo("0");
                                                    t16.setCallsign("0");
                                                    t16.setInlandShipMark("false");
                                                    t16.setNlane("2");
                                                    t16.setOrdercar(j+"");
                                                    t16.setShipTypeName(t.getShipTypeName());
                                                    t16.setLength(t.getLength());
                                                    t16.setWidth(t.getWidth());
                                                    t16.setShipTypeClassName(t.getShipTypeClassName());
                                                    t16.setState("0");

                                                    t16.setName("tt");
                                                    t16.setDelay(delay.toString());
                                                    t16.setNlane(nLane);
                                                    t16.setCog(cog);
                                                    t16.setDirection(direction);
                                                    commaIndex=zb7.indexOf(',');
                                                    t16.setLon(zb7.substring(0, commaIndex));
                                                    t16.setLat(zb7.substring(commaIndex + 1));
                                                    t16.setState("0");
                                                    t16.setGreen(green);
                                                    t16.setBefor(befor+"");
                                                    t16.setUsetime(usetime);
                                                    t16.setAlltime(alltime);
                                                    t16.setnLaneNo(nLaneNo);
                                                    list2.add(t16);
                                                }
                                                int count = 0;
                                                dealTime(msg.stuStates[i].nLane,list2);
                                                for (Trajectory trac : list2) {
                                                    count += JdbcUtils.insert(trac);
                                                }
                                                System.out.println("插入轨迹数量："+list2.size());
                                                System.out.println("成功插入数量："+ count);
                                                JdbcUtils.updateTrajectory();
                                            //}
                                        }
                                    }
                                }catch(Exception e1) {
                                    e1.printStackTrace();
                                }finally {
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                }
                default:

                    break;
            }
            return 0;
        }

        private Random random = new Random();
        private int getRandom(){
            return random.nextInt(2)+1;
        }

        private void dealTime(int nLane,List<Trajectory> list2) {
            for (Trajectory trajectory : list2) {
                // 3，4 直行

                // 1 右转

                // 2，5 左转

            }
        }
        public LocalDateTime toLocalDateTime(NetSDKLib.NET_TIME_EX UTC){
            return LocalDateTime.of(UTC.dwYear, UTC.dwMonth, UTC.dwDay, UTC.dwHour, UTC.dwMinute, UTC.dwSecond);
        }
        public String formateLocalDateTime(LocalDateTime localDateTime){
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            return localDateTime.format(dateTimeFormatter);
        }
    }




    /**
     * 停止侦听智能事件
     */
    public void DetachEventRealLoadPic() {
        if (this.attachHandle.longValue() != 0) {
            netSdk.CLIENT_StopLoadPic(this.attachHandle);
        }
    }
    public void RunTest()
    {
        System.out.println("Run Test");
        CaseMenu menu = new CaseMenu();;
        menu.addItem((new CaseMenu.Item(this , "AttachEventRealLoadPic" , "AttachEventRealLoadPic")));
        menu.addItem((new CaseMenu.Item(this , "DetachEventRealLoadPic" , "DetachEventRealLoadPic")));

        menu.run();
    }

    public static void main(String[] args) {
        RealLoadPicExDemo2 realLoadPicExDemo= null;
        try {
            realLoadPicExDemo = new RealLoadPicExDemo2();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


        Initialization.InitTest("10.238.87.39", 37777, "admin", "huichen123!@#");
        realLoadPicExDemo.RunTest();
        LoginOut();

    }
}